<template>
<!-- 登录页面 -->
  <div>
    <Row class="container">
      <i-col span="13" offset="2" class="login-img-box">
        <img src="../assets/sale.jpg" alt="">
      </i-col>
      <i-col span="7" class="login-box">
        <div class="login-container">
          <div class="login-header">
            <p>欢迎注册</p>
          </div>
          <div class="form-box">
            <Form ref="formInline" :model="registerForm" :rules="ruleInline">
              <FormItem prop="username">
                  <i-input type="text" v-model="registerForm.username" clearable size="large" placeholder="用户名">
                      <Icon type="person" slot="prepend"></Icon>
                  </i-input>
              </FormItem>
              <FormItem prop="password">
                  <i-input type="password" v-model="registerForm.password" clearable size="large" placeholder="密码">
                      <Icon type="ios-locked-outline" slot="prepend"> </Icon>
                  </i-input>
              </FormItem>
              <FormItem>

                  <Button type="error" size="small" @click="Register" long>注册</Button>
              </FormItem>
          </Form>
          </div>
        </div>
      </i-col>
    </Row>
  </div>
</template>

<script>

export default {
  name: 'Login',
  data () {
    return {
      registerForm: {
        username: '',
        password: ''
      },
      msg:'',
      ruleInline: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { type: 'string', min: 6, message: '密码不能少于6位', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {

    Register(){
      //  console.log("登录成功");
       this.$axios
        .post("userRegister", {
          params:this.registerForm
        })
        .then(result => {
          console.log(result);
          // this.msg = result.msg;
          this.msg=result.data.msg
          // console.log(this.msg);
          if (result.data.code !== 200)  return this.$message.error(this.msg);
          //  window.localStorage.setItem('token',res.data.token)
          window.sessionStorage.setItem("token", result.data.token);
          this.$message.success(this.msg);
          this.$router.push({ path: "login" })
        })
        .catch(err => {
          console.log(err);
        });
       
    }
  },

};
</script>

<style scoped>
.container {
  margin-top: 30px;
  height: 485px;
  background-color: #fff;
}
.login-img-box {
  height: 485px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-img-box>img {
  width: 68%;
}
.login-box {
  height: 485px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-container {
  width: 80%;
  height: 280px;
  border: #ED3F14 solid 1px;
}
.login-header {
  height: 50px;
  font-size: 20px;
  text-align: center;
  line-height: 50px;
  letter-spacing: 5px;
  color: #fff;
  background-color: #ED3F14;
}
.form-box {
  width: 80%;
  margin: 30px auto;
}
</style>
